package mpcs.utils
{
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;
	import flash.utils.ByteArray;
	
	import mpcs.model.vo.GlobalVO;
	
	import mx.core.FlexGlobals;
	import mx.graphics.ImageSnapshot;
	import mx.graphics.codec.PNGEncoder;
	import mx.printing.FlexPrintJob;

	public class MapUtils {
		
		public static var fileCount:int = 0;
		
		public function MapUtils() {
		}
		
		/**
		 * 保存快照至桌面文件
		 */		
		public static function saveHandler():void{
			
			fileCount ++;
			
			var file:File = File.desktopDirectory.resolvePath("MpcsMap-" + fileCount + ".png");
			var stream:FileStream = new FileStream();
			var en:PNGEncoder = new PNGEncoder(); 
			stream.open(file,FileMode.WRITE);
			var ba:ByteArray=en.encode(ImageSnapshot.captureBitmapData(GlobalVO.mpcsApp.gmap));
			stream.writeBytes(ba);
			stream.close();
		}
		
		/**
		 * 打印快照
		 */		
		public static function printHandler():void{
			var printJob:FlexPrintJob = new FlexPrintJob();
			if (printJob.start()) {
				printJob.addObject( GlobalVO.mpcsApp.gmap, 'FILL_PAGE');
			}
			printJob.send();
		}
		
		
	}
}